package com.yincheng.oes.business.controller;

import com.yincheng.oes.business.model.dto.DownloadFileDTO;
import com.yincheng.oes.business.model.query.DownloadListReq;
import com.yincheng.oes.business.model.query.ExportStudentPaperReq;
import com.yincheng.oes.business.model.result.BusinessResult;
import com.yincheng.oes.business.service.ExportService;
import com.yincheng.oes.business.util.Tools;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: yangsy
 * @Contact: 446948434@qq.com
 * @Date: 2021/9/5 17:18
 * @Version: 1.0
 * @Description:
 */
@Controller
@RequestMapping("/export")
public class ExportController {

    private final ExportService exportService;

    public ExportController(ExportService exportService) {
        this.exportService = exportService;
    }

    @RequestMapping(value = "/word/exportStudentPapers.json", method = RequestMethod.POST)
    @ResponseBody
    public BusinessResult exportStudentPapers(@RequestBody ExportStudentPaperReq req) {
        return exportService.exportStudentPapers(req);
    }

    @RequestMapping(value = "/downloadList.html", method = RequestMethod.GET)
    public String downloadList() {
        return "business/export/downloadList";
    }

    /**
     * 分页查询我的下载文件
     *
     * @param req 分页查询参数
     * @return 我的文件
     */
    @RequestMapping(value = "/getList.json", method = RequestMethod.GET)
    @ResponseBody
    public String list(DownloadListReq req) {
        Pair<Integer, List<DownloadFileDTO>> pair = exportService.getListByParam(req);
        return Tools.toEasyuiDataGrid(pair.getLeft(), pair.getRight());
    }

}
